package main

import (
	"fmt"
	"reflect"
)
/**
使用Interface方法进行类型推断和转换
 */
func main() {
	type user struct {
		Name string
		Age int
	}
	type person struct {
		Name string
		Age int
	}

	u := user{
		"q.yuhen",
		60,
	}

	v := reflect.ValueOf(&u)
	if !v.CanInterface() {
		println("CanInterface :fail.")
		return
	}
	p,ok := v.Interface().(*person)
	if !ok {
		println("Interface :fail.")
	} else {
		p.Age++
		fmt.Printf("%+v\n",u)
		return
	}

	m,ok := v.Interface().(*user)
	if !ok {
		println("Interface :fail.")
		return
	}
	m.Age++
	fmt.Printf("%+v\n",u)
}

